package com.flong.desgin.patterns.interfacesegregationprinciple;

import lombok.var;

/**
 * @Author:liangjl
 * @Date: 2020/3/7-18:11
 * @Eamil:jilongliang@sina.com
 * @Description:
 */
public class InterfaceSegregationPrinciple2 {

    public static void main(String[] args) {
        var c= new C1();
        c.depend1(new B1());
        c.depend2(new A1());
        c.depend3(new A1());

        D1 d= new D1();
        d.depend4(new B1());
        d.depend5(new B1());
    }
}

/**
 * 接口
 */
interface MyInterface1 {
    void operation1();
}

interface MyInterface2 {
    void operation2();

    void operation3();
}

interface MyInterface3 {
    void operation4();

    void operation5();
}

class A1 implements MyInterface1, MyInterface2 {
    @Override
    public void operation1() {
        System.out.println("A1实现1");
    }

    @Override
    public void operation2() {
        System.out.println("A1实现2");
    }

    @Override
    public void operation3() {
        System.out.println("A1实现3");
    }

}


class B1 implements MyInterface1, MyInterface3 {
    @Override
    public void operation1() {
        System.out.println("B1实现1");
    }

    @Override
    public void operation4() {
        System.out.println("B1实现4");
    }

    @Override
    public void operation5() {
        System.out.println("B1实现5");
    }
}

/**
 * C1只是依赖MyInterface1与MyInterface2的operation1、operation2、operation3
 */
class C1 {

    public void depend1(MyInterface1 interface1) {
        interface1.operation1();
    }

    public void depend2(MyInterface2 interface1) {
        interface1.operation2();
    }

    public void depend3(MyInterface2 interface1) {
        interface1.operation3();
    }

}

/**
 * D1只是依赖MyInterface3的operation4、operation5
 */
class D1 {

    public void depend4(MyInterface3 interface1) {
        interface1.operation4();
    }

    public void depend5(MyInterface3 interface1) {
        interface1.operation5();
    }

}